package com.fastCms.customer.frame.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.Collections;

/**
 * Created by foxx on 2018/6/25
 */
@EnableSwagger2
@Configuration
public class Swagger2Config {
    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()// 选择那些路径和api会生成document
                .apis(RequestHandlerSelectors.basePackage("com.fastCms.customer"))// 对所有controller下的api进行监控
                .paths(PathSelectors.any())// 对所有路径进行监控
                .build()
                .apiInfo(apiInfo());
    }

    private ApiInfo apiInfo() {
        String str =
                "  <p>1.ResultCodeConst为常用错误返回码</p>";
        return new ApiInfo(
                "Customer-哈密瓜管理系统",
                "<pre><code>注意：所有的api接口默认返回格式为：\n" +
                        "{\n" +
                        "  \"code\": 1,\n" +
                        "  \"data\": [\n" +
                        "  ],\n" +
                        "  \"msg\": \"success\"\n" +
                        "}</code></pre>" + str,
                "1.0.0",
                "关于api说明.",
                new Contact("admin", "192.192.192.192", "lsquan@163.com"),
                "License of API", "API license URL", Collections.emptyList());
    }

}
